<template>
  <div class="app_content_container">
    <Breadcrumb :items="['插件管理']" />
    <ga-button class="fr" type="primary" @click="$refs.addOrEditRef.open()">
      创建
    </ga-button>
    <div class="card_info">
      <div class="card_item" v-for="item in tableData" :key="item?.id">
        <div class="icon_box">
          <icon-edit
            style="margin-right: 8px"
            class="icon_color"
            @click="$refs.addOrEditRef.open()"
          />
          <icon-delete class="icon_color" @click="handleDelete" />
        </div>
        <div class="flex_between_aligncenter info_box">
          <ga-image
            width="200px"
            height="52px"
            src="https://p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/a8c8cdb109cb051163646151a4a5083b.png~tplv-uwbnlip3yd-webp.webp"
            footerPosition="outer"
            :style="{ margin: '48px 0 32px' }"
          />
          <ga-button
            class="find_btn"
            long
            type="primary"
            @click="
              $router.push(`/plugin-mgmt/detail/${record?.id}?name=${record?.name}`)
            "
          >
            查看详情
          </ga-button>
          <p class="info_txt">蓝鲸智云</p>
        </div>
      </div>
    </div>
    <!-- <ga-empty v-else style="margin-top: 15%" /> -->
  </div>
  <addOrEdit ref="addOrEditRef" @fetchData="fetchData" />
</template>

<script setup>
import { ref, computed } from "vue";
import { getPluginMgmtList, deletePluginMgmt } from "@/api/pluginMgmt.ts";
import addOrEdit from "./addOrEdit.vue";
import { deleteModalWithRefresh } from "@/hooks/useWarningModal";

// import useLoading from "@/hooks/loading";
// const { loading, setLoading } = useLoading(true);
const tableData = ref([{}, {}, {}, {}, {}]);
const addOrEditRef = ref();
// 获取列表
const fetchData = async () => {
  // setLoading(true);
  try {
    const { data } = await getPluginMgmtList({ limit: -1 });
    tableData.value = data.items;
    // total.value = data.total;
  } finally {
    // setLoading(false);
  }
};
// 删除方法
const handleDelete = (record) => {
  deleteModalWithRefresh(record, deletePluginMgmt, () => fetchData());
};
</script>

<style lang="scss" scoped>
.app_content_container {
  .card_info {
    padding: 0 16px;
    // height: calc(100vh - 180px);
    overflow-y: auto;
    display: flex;
    margin-top: 48px;
    flex-wrap: wrap;
    .card_item {
      height: 190px;
      position: relative;
      margin: 16px 16px 0 0;
      border: 1px solid #e2e8f4;
      border-radius: 6px;
      padding: 12px;
      width: calc((100% - 3 * 16px) / 4);
      transition: border-color 0.3s;
      flex-shrink: 0;
      background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
      &:nth-child(4n) {
        margin-right: 0;
      }
      &:nth-child(-n + 4) {
        margin-top: 0 !important;
      }
    }
  }
  .info_box {
    flex-direction: column;
  }
  .find_btn {
    display: none;
  }
  .icon_box {
    position: absolute;
    top: 8px;
    right: 8px;
    display: none;
    .icon_color {
      cursor: pointer;
    }
  }
  .card_item:hover .icon_box {
    display: block;
  }
  .card_item:hover .find_btn {
    display: block;
  }
  .card_item:hover .info_txt {
    display: none;
  }
}
</style>
